package com.aaa.service.impl;

import com.aaa.dao.MenuDao;
import com.aaa.dao.RoleDao;
import com.aaa.entity.Menu;
import com.aaa.entity.Role;
import com.aaa.exception.SaveRoleMenuException;
import com.aaa.service.RoleService;
import com.aaa.util.DefaultMsg;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;



@Service
@Transactional
public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleService {
    @Resource
    MenuDao menuDao;
    @Override
    public DefaultMsg insertPermit(Integer rid, String mids) {
        DefaultMsg defaultMsg=new DefaultMsg();
        menuDao.deleteOldQx(rid);
        //把参数数组mids转成list有序列表
        List<Double> list=new Gson().fromJson(mids,List.class);
        for (Double mid:list
             ) {
            Integer list2=menuDao.insertPermit(rid,mid.intValue());
            if (list2<1){
                throw new SaveRoleMenuException("操作失败，后端报错");
            }
        }
        return defaultMsg;
    }
}
